﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using System.IO;

namespace WPFTest
{
    
    class OzImageTextFrame : OzFrame
    {
        private BitmapSource image;
        private string text;

        public string Text
        {
            get { return this.text; }
            set { this.text = value; }
        }

        public OzImageTextFrame(BitmapSource image,string text)
        {
            this.image = image;
            this.text = text;
            this.frameName = "ImageTextFrame";
            
        }

        

        public BitmapSource Image
        {
            get { return this.image; }
            set { this.image = value; }
        }

        public override void Write(TextWriter writer, int index, string outFolder)
        {
            writer.WriteLine("<div id='classTextFrame'>");
            writer.WriteLine(Text);
            writer.WriteLine("</div>");

            writer.WriteLine("<div id='classImageFrame'>");
            writer.WriteLine("<img class='classImage' src='image_" + index.ToString() + ".png" + "' />");
            writer.WriteLine("</div>");

            SaveImageToFile(index, outFolder);
        }

        private void SaveImageToFile(int index, string outFolder)
        {
            FileStream fStream = new FileStream(outFolder + "image_" + index.ToString() + ".png", FileMode.Create);
            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(image));
            encoder.Save(fStream);
            fStream.Close();
        }

        public override string ToString()
        {
            return this.text;
        }
    }
}
